
//
//  CloudTagsViewController.swift
//  elarc01
//
//  Created by elarc on 16/6/21.
//  Copyright © 2016年 elarc. All rights reserved.
//

import UIKit
import RandomColorSwift

class CloudTagsViewController: BaseUIViewController{

    var cloudTags:DBSphereView?
    override func viewDidLoad() {
        super.viewDidLoad()
        cloudTags = DBSphereView()
//        cloudTags?.backgroundColor = UIColor.redColor()
        cloudTags?.frame = CGRectMake(40, 164, 320, 320)
        self.view.addSubview(cloudTags!)
        let array = NSMutableArray(capacity:0)
        
        for index in 0...50 {
            
            let btn = UIButton(type:.System)
            btn.setTitle("ee"+String(index), forState: .Normal)
            btn.setTitleColor(randomColor(hue: .Random, luminosity: .Random), forState: .Normal)
            btn.backgroundColor = randomColor(hue: .Random, luminosity: .Random)
            btn.titleLabel?.font = UIFont.systemFontOfSize(24)
            btn.frame = CGRectMake(0, 0, 60, 30)
            btn.addTarget(self, action: #selector(CloudTagsViewController.buttonPressed(_:)), forControlEvents: .TouchUpInside)
            array.addObject(btn)
            cloudTags?.addSubview(btn)
        }
        cloudTags?.setCloudTags(array as [AnyObject])
        
    }
    
    func buttonPressed(btn:UIButton) -> Void {
        
        cloudTags?.timerStop()
        UIView.animateWithDuration(0.3, animations: {
            btn.transform = CGAffineTransformMakeScale(2, 2)
            }) { (finished) in
                UIView.animateWithDuration(0.3, animations: {
                    btn.transform = CGAffineTransformMakeScale(1, 1)
                    }, completion: { (finished) in
                        self.cloudTags?.timerStart()
                })
        }
    }
    
}
